package com.example.demo;

import java.lang.reflect.Field;
import java.util.List;

public class ThreadLocalDemo {
    ThreadLocalDemo threadLocalDemo = new ThreadLocalDemo(){
        @Override
        public void test(String s,boolean isGC)  {
            try {
                ThreadLocal<Object> objectThreadLocal = new ThreadLocal<>();
                objectThreadLocal.set(s);
                if (isGC) {
                    System.gc();
                }
                Thread t = Thread.currentThread();
                Class<? extends Thread> clz = t.getClass();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    };
    public static void main(String[] args) throws NoSuchFieldException, IllegalAccessException, InterruptedException {

//        Thread t = new Thread(()->test("abc",false));
//        t.start();
//        t.join();
//        System.out.println("--gc后--");
//        Thread t2 = new Thread(() -> test("def", true));
//        t2.start();
//        t2.join();
//        System.out.println("sdfdf");
    }

    public void test(String s,boolean isGC)  {
        try {
            ThreadLocal<Object> objectThreadLocal = new ThreadLocal<>();
            objectThreadLocal.set(s);
            if (isGC) {
//                System.gc();
            }
            Thread t = Thread.currentThread();
            Class<? extends Thread> clz = t.getClass();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}